Imports System.Data.SqlClient

Public Class cls_config_producto

    Implements ICloneable

#Region "Variables ..."
    Private str_nombre As String = ""
    Private str_descripcion As String = ""
    Private str_splash As String = ""
    Private str_versiondb As String = ""
    Private str_reporte As String = ""
    Private str_logo As String = ""
#End Region

#Region "Propiedades ..."
    Property nombre() As String
        Get
            nombre = str_nombre
        End Get
        Set(ByVal value As String)
            str_nombre = value
        End Set
    End Property
    Property descripcion() As String
        Get
            descripcion = str_descripcion
        End Get
        Set(ByVal value As String)
            str_descripcion = value
        End Set
    End Property
    Property splash() As String
        Get
            splash = str_splash
        End Get
        Set(ByVal value As String)
            str_splash = value
        End Set
    End Property
    Property versiondb() As String
        Get
            versiondb = str_versiondb
        End Get
        Set(ByVal value As String)
            str_versiondb = value
        End Set
    End Property
    Property reporte() As String
        Get
            reporte = str_reporte
        End Get
        Set(ByVal value As String)
            str_reporte = value
        End Set
    End Property
    Property logo() As String
        Get
            logo = str_logo
        End Get
        Set(ByVal value As String)
            str_logo = value
        End Set
    End Property
#End Region

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre"))) = False Then
            str_nombre = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion"))) = False Then
            str_descripcion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("splash"))) = False Then
            str_splash = (obj_Reader.GetValue(obj_Reader.GetOrdinal("splash")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("versiondb"))) = False Then
            str_versiondb = (obj_Reader.GetValue(obj_Reader.GetOrdinal("versiondb")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("reporte"))) = False Then
            str_reporte = (obj_Reader.GetValue(obj_Reader.GetOrdinal("reporte")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("logo"))) = False Then
            str_logo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("logo")))
        End If
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_producto_Modificar"
                .Parameters.Add("@nombre", SqlDbType.NVarChar).Value = str_nombre
                .Parameters.Add("@descripcion", SqlDbType.NVarChar).Value = str_descripcion
                .Parameters.Add("@splash", SqlDbType.NVarChar).Value = str_splash
                .Parameters.Add("@versiondb", SqlDbType.NVarChar).Value = str_versiondb
                .Parameters.Add("@reporte", SqlDbType.NVarChar).Value = str_reporte
                .Parameters.Add("@logo", SqlDbType.NVarChar).Value = str_logo
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de config_producto." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar() As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_producto_Buscar"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscar el registro de config_producto." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_config_productoClon As New cls_config_producto
        obj_config_productoClon.str_nombre = Me.str_nombre
        obj_config_productoClon.str_descripcion = Me.str_descripcion
        obj_config_productoClon.str_splash = Me.str_splash
        obj_config_productoClon.str_versiondb = Me.str_versiondb
        obj_config_productoClon.str_reporte = Me.str_reporte
        obj_config_productoClon.str_logo = Me.str_logo
        Return obj_config_productoClon
    End Function

End Class
